/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConsultaEleccion.java
 *
 * Created on 14/11/2010, 05:00:15 PM
 */
package zonasoft.Vistas.Funcionales;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import org.jdesktop.swingx.decorator.Filter;
import org.jdesktop.swingx.decorator.FilterPipeline;
import org.jdesktop.swingx.decorator.PatternFilter;
import zonasoft.Conceptos.Lider;
import zonasoft.Conceptos.Zonificados;
import zonasoft.Manejadores.ManejadorBaseDatos;
import zonasoft.Manejadores.ManejadorLider;
import zonasoft.Manejadores.ManejadorZonificados;
import zonasoft.Vistas.Negocio.Novedades;

/**
 *
 * @author JORGE
 */
public class ListarLideres extends javax.swing.JDialog {

    private List<Zonificados> zonificadosDelLider=new ArrayList<Zonificados>();
    /** Creates new form ConsultaEleccion */
    public ListarLideres(java.awt.Frame parent) {
        super(parent, true);
        initComponents();
        pack();
        Rectangle parentBounds = parent.getBounds();
        Dimension size = getSize();
        // Center in the parent
        int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2);
        int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2);
        setLocation(new Point(x, y));

        List<TableColumn> columnas=  tablaLideres.getColumns();
       columnasTablaSimpa.addItem("..Sin filtro...");
        for (TableColumn tableColumn : columnas) {
            String col= tableColumn.getHeaderValue().toString().trim();
            columnasTablaSimpa.addItem(col);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXTaskPaneContainer1 = new org.jdesktop.swingx.JXTaskPaneContainer();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        aceptar = new javax.swing.JButton();
        listar = new javax.swing.JButton();
        limpiar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaLideres = new org.jdesktop.swingx.JXTable();
        totalSim = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        textAreaDatosVotacion = new javax.swing.JTextArea();
        columnasTablaSimpa = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        filtroText = new javax.swing.JTextField();
        errorLabel = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaZonificados = new org.jdesktop.swingx.JXTable();
        totalSimp = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        campoClasi = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tablaNovedad = new org.jdesktop.swingx.JXTable();
        jLabel7 = new javax.swing.JLabel();
        totalSimp1 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();

        setTitle("");
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 20));
        jLabel1.setText("Listado de Lideres");
        jXTaskPaneContainer1.add(jLabel1);

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.black, java.awt.Color.black, java.awt.Color.darkGray, java.awt.Color.darkGray));

        aceptar.setFont(new java.awt.Font("Tahoma", 1, 12));
        aceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/ok 32.png"))); // NOI18N
        aceptar.setText("Aceptar");
        aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aceptarActionPerformed(evt);
            }
        });

        listar.setFont(new java.awt.Font("Tahoma", 1, 12));
        listar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/community-users-icon2.png"))); // NOI18N
        listar.setText("Listar");
        listar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listarActionPerformed(evt);
            }
        });

        limpiar.setFont(new java.awt.Font("Tahoma", 1, 12));
        limpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/limpiar.png"))); // NOI18N
        limpiar.setText("Limpiar");
        limpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limpiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(aceptar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                    .addComponent(listar, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                    .addComponent(limpiar, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(listar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(limpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(aceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.gray, java.awt.Color.lightGray, java.awt.Color.darkGray, java.awt.Color.gray), "Lideres", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        tablaLideres.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.blue, new java.awt.Color(51, 102, 255)));
        tablaLideres.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "IdLider", "Nombre","      Apellido      ","Edad","       correo       ","telefono","  direccion  "
            }
        ));
        tablaLideres.setEditable(false);
        tablaLideres.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaLideresMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tablaLideres);

        totalSim.setEditable(false);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel4.setText("Actualmente hay:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel5.setText("Lideres Registrados");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 609, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(totalSim, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(totalSim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)))
        );

        jXPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), "Datos de votacion", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        textAreaDatosVotacion.setColumns(20);
        textAreaDatosVotacion.setEditable(false);
        textAreaDatosVotacion.setFont(new java.awt.Font("Tahoma", 0, 10));
        textAreaDatosVotacion.setRows(5);
        jScrollPane3.setViewportView(textAreaDatosVotacion);

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                .addContainerGap())
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                .addContainerGap())
        );

        columnasTablaSimpa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                columnasTablaSimpaActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel6.setText("Filtrar Por");

        filtroText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                filtroTextKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                filtroTextKeyReleased(evt);
            }
        });

        errorLabel.setForeground(new java.awt.Color(255, 0, 0));
        errorLabel.setText("No  ha seleccionado ningun filtro...");

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.lightGray, java.awt.Color.lightGray, java.awt.Color.darkGray, java.awt.Color.darkGray));

        tablaZonificados.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.blue, new java.awt.Color(51, 102, 255)));
        tablaZonificados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Id", "Nombre"," Apellido "," correo","telefono"
            }
        ));
        tablaZonificados.setEditable(false);
        tablaZonificados.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaZonificadosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tablaZonificados);

        totalSimp.setEditable(false);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setText("Actualmente posee:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel3.setText("Zonificados Asociados");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(totalSimp, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addGap(79, 79, 79)
                        .addComponent(campoClasi, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 624, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(14, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(campoClasi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(totalSimp)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Zonificados", jPanel1);

        tablaNovedad.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.blue, new java.awt.Color(51, 102, 255)));
        tablaNovedad.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Lider", "Zonificado","Descripcion"
            }
        ));
        tablaNovedad.setEditable(false);
        tablaNovedad.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaNovedadMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(tablaNovedad);

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel7.setText("Actualmente posee:");

        totalSimp1.setEditable(false);

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel8.setText("Novedades Registradas");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(totalSimp1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel8)
                .addContainerGap(291, Short.MAX_VALUE))
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addGap(16, 16, 16)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 616, Short.MAX_VALUE)
                    .addGap(16, 16, 16)))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(174, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(totalSimp1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)))
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addGap(28, 28, 28)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(39, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("Novedades", jPanel4);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXTaskPaneContainer1, javax.swing.GroupLayout.DEFAULT_SIZE, 933, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 653, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addComponent(columnasTablaSimpa, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(28, 28, 28)
                                .addComponent(filtroText, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(errorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(60, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jXTaskPaneContainer1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(columnasTablaSimpa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(filtroText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(errorLabel))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(99, 99, 99)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void listarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listarActionPerformed
        // TODO add your handling code here:
        limpiarTabla();
        limpiarTablaZ();
        listaLideres();
        limpiarTablaN();
//            listaZonificados();
    }//GEN-LAST:event_listarActionPerformed

    private void aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aceptarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_aceptarActionPerformed

    private void limpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limpiarActionPerformed
        // TODO add your handling code here:
        limpiarTabla();
        limpiarTablaZ();
        textAreaDatosVotacion.setText("");
    }//GEN-LAST:event_limpiarActionPerformed

    private void tablaLideresMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaLideresMouseClicked
        // TODO add your handling code here:

        ManejadorBaseDatos mb = ManejadorBaseDatos.getInstancia();
        List<Zonificados> z = new ArrayList<Zonificados>();
        List<String> novedades=new ArrayList<String>();
        int indice = 1;
        try {
            mb.conectar();
        } catch (Exception ex) {
            Logger.getLogger(ListarLideres.class.getName()).log(Level.SEVERE, null, ex);
        }

        ManejadorLider.conm = mb.getConexion();

        if (evt.getClickCount() == 1) {
            // trae el punto donde di clik en la fila, me trae la celda
            int fila = tablaLideres.rowAtPoint(evt.getPoint());
            // en que columna estoy, los dos me traen en que celda estoy
            int columna = tablaLideres.columnAtPoint(evt.getPoint());
            if ((fila > -1) && (columna > -1)) {
//                if (columna == 0) {
                columna=0;
                    int id = Integer.parseInt(tablaLideres.getValueAt(fila, columna).toString());

//                    System.out.println("id = " + id);
                    Lider l = null;
                    try {
                        l = ManejadorLider.getLider(String.valueOf(id));
                         z = l.getZonificados();
                         novedades=ManejadorLider.misNovedades(id);
                        listaZonificados(z);
                        listaNovedad(novedades);
                        zonificadosDelLider=z;
//                        System.out.println("l = " + l == null);
                    } catch (Exception ex) {
                        Logger.getLogger(ListarLideres.class.getName()).log(Level.SEVERE, null, ex);
                        ex.printStackTrace();
                    }

                } else {

                    JOptionPane.showMessageDialog(null, "Por favor de click en el id del Lider");
                }
//            }

        }
    }//GEN-LAST:event_tablaLideresMouseClicked

    private void tablaZonificadosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaZonificadosMouseClicked
        // TODO add your handling code here:
        ManejadorBaseDatos mb = ManejadorBaseDatos.getInstancia();
        Zonificados zonificadoActual=null;
        Map<String,String> resultados=null;
        int indice = 1;
        try {
            mb.conectar();
        } catch (Exception ex) {
            Logger.getLogger(ListarUsuarios.class.getName()).log(Level.SEVERE, null, ex);
        }

        ManejadorZonificados.con = mb.getConexion();

        if (evt.getClickCount() == 1) {

            int fila = tablaZonificados.rowAtPoint(evt.getPoint());
            int columna = tablaZonificados.columnAtPoint(evt.getPoint());
            if ((fila > -1) && (columna > -1)) {
//                if (columna == 0) {
                columna=0;
                    int id = Integer.parseInt(tablaZonificados.getValueAt(fila, columna).toString());

//                    System.out.println("id zonificado = " + id);
                    try {
                        zonificadoActual=buscarZonificado(id);
                        String idPuesto=zonificadoActual.getIdPuesto();
                        resultados=ManejadorZonificados.getDatosVotacion(idPuesto);

                    } catch (Exception ex) {
                        Logger.getLogger(ListarUsuarios.class.getName()).log(Level.SEVERE, null, ex);
                        ex.printStackTrace();
                    }

                } else {
                    JOptionPane.showMessageDialog(null, "Por favor de click en el id del Zonificado");
                }
//            }

        }

        if(zonificadoActual!=null)
        {
            String puesto=resultados.get("puesto");
            String barrio=resultados.get("barrio");
            String municipio=resultados.get("municipio");
            String departamento=resultados.get("departamento");
            String mesa=zonificadoActual.getNumeroMesa();
            String datos=" Puesto: "+puesto+"\n\n"+" Barrio: "+barrio+"\n\n"
                    +" Departamento: "+departamento+"\n\n"+" Municipio: "+municipio+"\n\n"+
                    " Mesa N°: "+mesa+"\n\n";
            textAreaDatosVotacion.setText(datos);
        }
    }//GEN-LAST:event_tablaZonificadosMouseClicked

    private void columnasTablaSimpaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_columnasTablaSimpaActionPerformed
        // TODO add your handling code here:
        hacerLosFiltros();
}//GEN-LAST:event_columnasTablaSimpaActionPerformed

    private void filtroTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_filtroTextKeyPressed
        // TODO add your handling code here:
        filtroTextKeyReleased(evt);
}//GEN-LAST:event_filtroTextKeyPressed

    private void filtroTextKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_filtroTextKeyReleased
        hacerLosFiltros();
}//GEN-LAST:event_filtroTextKeyReleased

    private void tablaNovedadMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaNovedadMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_tablaNovedadMouseClicked

    private void hacerLosFiltros()
    {
        try {
            limpiarTabla();
            // TODO add your handling code here:
            String filtro=filtroText.getText();
            int columna=columnasTablaSimpa.getSelectedIndex();
            if(columna>0 && !filtro.isEmpty() && filtro!=null)
            { errorLabel.setVisible(false);
                columna-=1;
            //FilterPipeline filtros = new FilterPipeline(new Filter[] { new PatternFilter(filtro, 0, 0),new PatternFilter(filtro,1, 1) });
            PatternFilter p1 =new PatternFilter(filtro, -1, columna);
                Filter[] filterArray = {p1};
	        FilterPipeline filters = new FilterPipeline(filterArray);

            tablaLideres.setFilters(filters);
            }
            else
            {
            Filter[] filterArray = {};
	    FilterPipeline filters = new FilterPipeline(filterArray);
            tablaLideres.setFilters(filters);
            if(columna==0 )
            errorLabel.setVisible(true);
            if(filtro==null || filtro.isEmpty())
                errorLabel.setVisible(false);
            }

            listaLideres();


        } catch (Exception ex) {
            Logger.getLogger(ListarLideres.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
        }
    }

    public void listaLideres() {
        Date fechaHoy = new Date();
        int edadLider = 0;
        Collection<Lider> lid = null;
        try {
            lid = (Collection<Lider>) ManejadorLider.listarLideres();
            Iterator i = lid.iterator();
            DefaultTableModel dtm = (DefaultTableModel) tablaLideres.getModel();
            tablaLideres.setFont(new java.awt.Font("Tahoma", 0, 13));
            Lider li = new Lider();
            while (i.hasNext()) {
                li = (Lider) i.next();
                // String fecha = String.valueOf(li.getFecha_registro());
             edadLider=fechaHoy.getYear()-li.getFechaNacimiento().getYear();
             String fechaNacimiento = li.getFechaNacimiento().toString();
//             int anos = edad(fechaNacimiento);
                System.out.println("anos = " + edadLider);
                Object[] fila = {li.getIdLider(), li.getNombre(), li.getApellido(), edadLider, li.getCorreo(), li.getTelefono(), li.getDireccion()};
                if (!li.getIdLider().endsWith("_")) {
                    dtm.addRow(fila);
                }
                int t=tablaLideres.getFilters().getOutputSize();
                //int r = dtm.getRowCount();
                totalSim.setText(String.valueOf(t));
            }
        } catch (Exception ex) {
            Logger.getLogger(ListarLideres.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
//    "Id", "Nombre"," Apellido "," correo","telefono"

    public void listaZonificados(List<Zonificados> zon) {
        Date fechaHoy = new Date();
        int edadZonificado = 0;
        try {
            Iterator i = zon.iterator();
            DefaultTableModel dtm = (DefaultTableModel) tablaZonificados.getModel();
            tablaZonificados.setFont(new java.awt.Font("Tahoma", 0, 13));
            Zonificados zo = new Zonificados();
            limpiarTablaZ();
            while (i.hasNext()) {
                zo = (Zonificados) i.next();
                // String fecha = String.valueOf(li.getFecha_registro());
//                    edadZonificado=fechaHoy.getYear()-zo.getFechadeNacimiento().getYear();
                Object[] fila = {zo.getIdZonificado(), zo.getNombres(), zo.getApellidos(), zo.getCorreo(), zo.getTelefono()};
                if (!zo.getIdLider().endsWith("_")) {
                    dtm.addRow(fila);
                }
                int r = dtm.getRowCount();
                totalSimp.setText(String.valueOf(r));
                int clasificacion = Integer.parseInt(totalSimp.getText());

                if(clasificacion ==0 ){
                  campoClasi.setText( "sin Zonificados");
                        }
                else if(clasificacion == 1 && clasificacion <= 5){
                  campoClasi.setText( "Rk");
                        }
                else if(clasificacion == 6 && clasificacion <= 15){
              campoClasi.setText( "A");
                        }else if(clasificacion == 16 && clasificacion <= 30){
                campoClasi.setText( "AA");
                        }else if(clasificacion == 30 && clasificacion <= 49){
               campoClasi.setText( "AAA");
                        }else if(clasificacion >= 50){
               campoClasi.setText(" Grandes Ligas");
                        }

            }
        } catch (Exception ex) {
            Logger.getLogger(ListarLideres.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
     public void listaNovedad(List<String> noved){
     
     //"Lider", "Zonificado"," Descripcion"
     List<String> novedades = null;
	 DefaultTableModel dtm = (DefaultTableModel)tablaNovedad.getModel();
	 try{
	   novedades =   noved;
           tablaNovedad.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
           tablaNovedad.setFont(new java.awt.Font("Tahoma",0,13));
             TableColumn tc = tablaNovedad.getColumn("Lider");
             tc.setPreferredWidth(106);
             TableColumn tc1 = tablaNovedad.getColumn("Zonificado");
             tc1.setPreferredWidth(186);
              TableColumn tc3 = tablaNovedad.getColumn("Descripcion");
             tc3.setPreferredWidth(506);
             limpiarTablaN();
             for (String dato : novedades) {
                 String[]nov=dato.split(",");
                 Object[]fila={nov[0],nov[1],nov[2]};
                 dtm.addRow(fila); 
             }//,nov[4],nov[5],nov[6]
             int r = dtm.getRowCount();
                totalSimp1.setText(String.valueOf(r));
//            }
	 }catch(Exception ex){
	  Logger.getLogger(Novedades.class.getName()).log(Level.SEVERE, null, ex);
	 }
 
     }

    public void limpiarTabla() {
        DefaultTableModel dtm = (DefaultTableModel) tablaLideres.getModel();
        dtm.setRowCount(0);
        totalSim.setText("");
    }

    public void limpiarTablaZ() {
        DefaultTableModel dtm = (DefaultTableModel) tablaZonificados.getModel();
        dtm.setRowCount(0);
        totalSimp.setText("");
    }
    
    public void limpiarTablaN() {
        DefaultTableModel dtm = (DefaultTableModel) tablaNovedad.getModel();
        dtm.setRowCount(0);
        totalSimp1.setText("");
    }

    public Zonificados buscarZonificado(int id)
    {
        Zonificados ztemp=null;
        for (Zonificados zonificados : zonificadosDelLider) {
            if(zonificados.getIdZonificado().equals(String.valueOf(id)))
            {
                ztemp=zonificados;
                 break;

            }
        }
        return ztemp;
    }


//
//    public int edad(String fecha_nac) {     //fecha_nac debe tener el formato dd/MM/yyyy
//
//    Date fechaActual = new Date();
//    SimpleDateFormat formato = new SimpleDateFormat("yyyy/dd/MM");
//    String hoy = formato.format(fechaActual);
//    String[] dat1 = fecha_nac.split("/");
//    String[] dat2 = hoy.split("/");
//
//    int anos = Integer.parseInt(dat2[2]) - Integer.parseInt(dat1[2]);
//    int mes = Integer.parseInt(dat2[1]) - Integer.parseInt(dat1[1]);
//    if (mes < 0) {
//      anos = anos - 1;
//    } else if (mes == 0) {
//      int dia = Integer.parseInt(dat2[0]) - Integer.parseInt(dat1[0]);
//      if (dia > 0) {
//        anos = anos - 1;
//      }
//    }
//    return anos;
//  }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aceptar;
    private javax.swing.JLabel campoClasi;
    private javax.swing.JComboBox columnasTablaSimpa;
    private javax.swing.JLabel errorLabel;
    private javax.swing.JTextField filtroText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXTaskPaneContainer jXTaskPaneContainer1;
    private javax.swing.JButton limpiar;
    private javax.swing.JButton listar;
    private org.jdesktop.swingx.JXTable tablaLideres;
    private org.jdesktop.swingx.JXTable tablaNovedad;
    private org.jdesktop.swingx.JXTable tablaZonificados;
    private javax.swing.JTextArea textAreaDatosVotacion;
    private javax.swing.JTextField totalSim;
    private javax.swing.JTextField totalSimp;
    private javax.swing.JTextField totalSimp1;
    // End of variables declaration//GEN-END:variables
}
